package es.mahulo.battleship.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import es.mahulo.battleship.api.dao.PlayerDao;
import es.mahulo.battleship.model.Player;

@Repository
public class PlayerDaoImpl implements PlayerDao {
	private EntityManager entityManager;
	@PersistenceContext  
    public void setEntityManager(EntityManager entityManager)   {  
		this.entityManager = entityManager;  
    }
	
	@Override
	@Transactional
	public Player create(final Player player) {
		entityManager.persist(player);
		return player;

	}

	@Override
	@Transactional
	public Player find(Long id) {
		return entityManager.find(Player.class, id);
		
	}

	@Override
	@Transactional
	public Player update(Player player) {
		return entityManager.merge(player);	
	}
}
